<?php
set_time_limit(0);
date_default_timezone_set('Asia/Shanghai');
$root_dir = realpath(dirname(__FILE__) . '/../../../');
define('APP_DIR', $root_dir . '/app/');
/*
require_once( $root_dir . '/config/config.php');
require ($root_dir . '/app/base/kernel.php');
include_once (APP_DIR . '/base/defined.php');
include_once (APP_DIR . '/base/lib/http.php');
if (!kernel :: register_autoload()){
    require (APP_DIR . '/base/autoload.php');
}*/
echo md5('FBEA0D04C17D338C2CCDEFC1BEEA519A1');
#exit;
require (APP_DIR . '/openapi/lib/curl.php');
$s = array (
  'sign' => '8E1EB47F1D67C7D638EC69D5E7FCBFA9',
  'timestamp' => '1468691',
  'content' => '{"SIGN_CODE":"1418807899046","OutInFlag":"","MEMBER_ORDER_NO":"201412170006","SI_NO":"LP1201482770504","status":"","wms_do":"120000000181","status_code":"0006","status_name":"已发货","REASON":"","operator":"zhuhyf","MESSAGE":"","status_time":"2014-12-17 00:00:00","PdLogisticsBaseNum_list":[{"TMSCODE":"1000001","name":"顺丰","mail_no":"14121701","status":"","PdLogisticsBaseDetail_items":[{"ITEM":"0001","CUSTID":"1300000001","STOCKID":"111000-01","erp_goods_bn":"TEST1","PRODUCT_NO":"TEST1","qty":"10.0"}]}]}',
  'flag' => 'WMS',
  'method' => 'ship.doUpdate',
);
$url = 'http://10.211.55.5/joymainoms/index.php/openapi/rpc/service/';
$core_http = new openapi_curl();
        $response = $core_http->set_timeout(10)->post($url,$s);
        echo('<pre>a');print_r($response);exit;
exit;
    class yyApi{

        public  $baseUrl = 'http://172.30.6.101/';
        //public  $baseUrl = 'http://172.16.1.32/';// 'http://172.30.6.101/';

        /*
          billtype
          30 销售订单
          4C  销售出库单
          45  采购入库单
          action = Save
        */
        /**
         * 单据添加
         *
         * @return void
         * @author 
         **/
        public function saveNCDJ($billtype,$action='Save',$xml)
        {
            $client = $this->getClient();
            $params['string'] = '';
            $params['string1'] = $billtype;
            $params['string2'] = $action;
            $params['string3'] = $xml;

            $res = $client->saveNCDJ($params);
            return (array)$res;
        }
        /**
         * 获取模板服务
         *
         * @return void
         * @author 
         **/
        public function getClient()
        {
            $url = $this->baseUrl.'uapws/service/IsaveNCDJByWMS?wsdl';
            echo('<pre>');print_r($url);
            $client = new SoapClient($url);
            return $client;
        }
    }
    $yyApi = new yyApi();
    $xml = '<?xml version="1.0" encoding="gb2312"?>
<ufinterface account="0001" billtype="30" filename="" groupcode="0001" isexchange="Y" replace="Y" roottag="" sender="SO1001">
    <bill id="">
        <billhead>
            <pk_group>0001</pk_group>
            <pk_org>001</pk_org>
            <pk_org_v>001</pk_org_v>
            <ctrantypeid>30-01</ctrantypeid>
            <vtrantypecode>30-01</vtrantypecode>
            <cbiztypeid>SO01</cbiztypeid>
            <vbillcode></vbillcode>
            <dbilldate>2014-12-16 18:05:16</dbilldate>
            <ccustomerid>F001</ccustomerid>
            <cdeptvid>010101</cdeptvid>
            <cdeptid>010101</cdeptid>
            <cemployeeid></cemployeeid>
            <corigcurrencyid>CNY</corigcurrencyid>
            <cinvoicecustid>F001</cinvoicecustid>
            <ntotalnum>11.00000000</ntotalnum>
            <ntotalorigmny>13.00000000</ntotalorigmny>         
            <vdef18></vdef18>           
            <vdef19></vdef19>
            <vdef20></vdef20>
            <billmaker>yy01</billmaker>
            <dmakedate>2014-12-16 18:05:16</dmakedate>
            <creator>yy01</creator>
            <creationtime>2014-12-16 18:05:16</creationtime>
            <approver>yy01</approver>
            <taudittime>2014-12-16 18:05:16</taudittime>
            <vnote></vnote>
            <so_saleorder_b>
                <item>
                    <pk_group>0001</pk_group>
                    <pk_org>001</pk_org>
                    <dbilldate>2014-12-16 18:05:16</dbilldate>
                    <crowno>10</crowno>
                    <cmaterialvid>0001</cmaterialvid>
                    <cmaterialid>0001</cmaterialid>
                    <cunitid>CHUANG</cunitid>
                    <castunitid>CHUANG</castunitid>
                    <nnum>11.00000000</nnum>
                    <nastnum>11.00000000</nastnum>
                    <nqtunitnum>11.00000000</nqtunitnum>
                    <ndiscountrate>100.00000000</ndiscountrate>
                    <nitemdiscountrate>100.00000000</nitemdiscountrate>
                    <ctaxcodeid>CN01</ctaxcodeid>
                    <ntaxrate>17.00000000</ntaxrate>
                    <ftaxtypeflag>1</ftaxtypeflag>
                    <ccurrencyid>CNY</ccurrencyid>
                    <nexchangerate>1.00000000</nexchangerate>
                    <nqtorigtaxprice>1.18000000</nqtorigtaxprice>
                    <nqtorigprice>1.01000000</nqtorigprice>
                    <nqtorigtaxnetprc>1.18000000</nqtorigtaxnetprc>
                    <nqtorignetprice>1.01000000</nqtorignetprice>
                    <norigtaxprice>1.18000000</norigtaxprice>
                    <norigprice>1.00000000</norigprice>
                    <norigtaxnetprice>1.18000000</norigtaxnetprice>
                    <norignetprice>1.01000000</norignetprice>
                    <ntax>1.89000000</ntax>
                    <ncaltaxmny>11.11000000</ncaltaxmny>
                    <norigmny>11.11000000</norigmny>
                    <norigtaxmny>13.00000000</norigtaxmny>
                    <nqttaxprice>1.18000000</nqttaxprice>
                    <nqtprice>1.01000000</nqtprice>
                    <nqttaxnetprice>1.18000000</nqttaxnetprice>
                    <nqtnetprice>1.01000000</nqtnetprice>
                    <ntaxprice>1.18000000</ntaxprice>
                    <nprice>1.01000000</nprice>
                    <ntaxnetprice>1.18000000</ntaxnetprice>
                    <nnetprice>1.01000000</nnetprice>
                    <nmny>11.11000000</nmny>
                    <ntaxmny>13.00000000</ntaxmny>
                    <vbatchcode></vbatchcode>
                    <blargessflag>N</blargessflag>
                    <dsenddate>2014-12-16 18:05:16</dsenddate>
                    <dreceivedate>2014-12-16 18:05:16</dreceivedate>
                    <creceivecustid>F001</creceivecustid>
                    <csendstockorgvid>001</csendstockorgvid>
                    <csendstockorgid>001</csendstockorgid>
                    <csendstordocid>0002</csendstordocid>
                    <csettleorgvid>001</csettleorgvid>
                    <csettleorgid>001</csettleorgid>
                    <crececountryid>CN</crececountryid>
                    <csendcountryid>CN</csendcountryid>
                    <ctaxcountryid>CN</ctaxcountryid>
                    <fbuysellflag>1</fbuysellflag>
                    <btriatradeflag>N</btriatradeflag>
                    <carorgvid>001</carorgvid>
                    <carorgid>001</carorgid>
                    <cprofitcentervid></cprofitcentervid>
                    <cprofitcenterid></cprofitcenterid>    
                    <fretexchange>0</fretexchange>
                    <vbdef19></vbdef19>              
                    <vbdef20>中</vbdef20>                         
                </item>
            </so_saleorder_b>
        </billhead>
    </bill>
</ufinterface>';
$encode = mb_detect_encoding($xml, array("ASCII","UTF-8","GB2312","GBK")); 
if ($encode == "UTF-8"){ 
    #$xml = iconv("UTF-8","GB2312",$xml); 
} 
error_log(''.var_export($xml,1)."\r\n",3,__FILE__.'.log');
echo $encode;
    $res = $yyApi->saveNCDJ('30','save',$xml);
    error_log(''.var_export($res,1)."\r\n",3,__FILE__.'.log');
    echo('<pre>');print_r($res);exit;
?>
